<template>
  <div class="document-management">
    <!-- 顶部导航栏 -->
    <div class="header">
      <div class="header-left">
        <div class="logo">
          <span class="logo-icon">📚</span>
          <span class="logo-text">在线国际教育APP</span>
        </div>
      </div>
      <div class="header-right">
        <span class="user-info">欢迎您，admin</span>
        <el-button type="text" @click="logout" class="logout-btn">退出登录</el-button>
      </div>
    </div>

    <div class="main-container">
      <!-- 左侧菜单 -->
      <div class="sidebar">
        <el-menu
          default-active="document-management"
          class="sidebar-menu"
          background-color="#f5f5f5"
          text-color="#333"
          active-text-color="#409EFF"
        >
          <el-menu-item index="system-overview">
            <span>系统概览</span>
          </el-menu-item>
          <el-menu-item index="user-management">
            <span>用户一管理</span>
          </el-menu-item>
          <el-menu-item index="student-management">
            <span>学生管理</span>
          </el-menu-item>
          <el-menu-item index="teacher-management">
            <span>教师管理</span>
          </el-menu-item>
          <el-menu-item index="category-management">
            <span>分类管理</span>
          </el-menu-item>
          <el-menu-item index="course-management">
            <span>课程管理</span>
          </el-menu-item>
          <el-menu-item index="order-management">
            <span>订单管理</span>
          </el-menu-item>
          <el-menu-item index="document-management">
            <span>文档管理</span>
          </el-menu-item>
          <el-menu-item index="revenue-management">
            <span>收入管理</span>
          </el-menu-item>
        </el-menu>
      </div>

      <!-- 主要内容区域 -->
      <div class="content">
        <div class="content-header">
          <h2>文档管理</h2>
        </div>

        <!-- 搜索区域 -->
        <div class="search-section">
          <el-form :model="searchForm" inline class="search-form">
            <el-form-item>
              <el-input
                v-model="searchForm.keyword"
                placeholder="关键字"
                clearable
                style="width: 200px"
              />
            </el-form-item>
            <el-form-item>
              <el-date-picker
                v-model="searchForm.createTime"
                type="date"
                placeholder="创建时间"
                style="width: 200px"
                format="YYYY-MM-DD"
                value-format="YYYY-MM-DD"
              />
            </el-form-item>
            <el-form-item>
              <el-input
                v-model="searchForm.category"
                placeholder="类型分类"
                clearable
                style="width: 200px"
              />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="handleSearch">搜索</el-button>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="handleAdd">新增</el-button>
            </el-form-item>
          </el-form>
        </div>

        <!-- 数据表格 -->
        <div class="table-section">
          <el-table
            :data="tableData"
            style="width: 100%"
            border
            stripe
            v-loading="loading"
          >
            <el-table-column prop="id" label="序号" width="80" align="center" />
            <el-table-column prop="fileName" label="文档名称" min-width="300">
              <template #default="scope">
                <div class="file-name">
                  <el-icon class="file-icon"><Document /></el-icon>
                  <span>{{ scope.row.fileName }}</span>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="fileSize" label="文档大小" width="120" align="center" />
            <el-table-column prop="uploadTime" label="上传时间" width="180" align="center" />
            <el-table-column label="操作" width="100" align="center" fixed="right">
              <template #default="scope">
                <el-button
                  type="primary"
                  size="small"
                  @click="handleEdit(scope.row)"
                  link
                >
                  删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>

        <!-- 分页 -->
        <div class="pagination-section">
          <div class="pagination-info">
            显示第1-4条记录，共4条
          </div>
          <el-pagination
            v-model:current-page="currentPage"
            v-model:page-size="pageSize"
            :page-sizes="[10, 20, 50, 100]"
            :total="total"
            layout="prev, pager, next, sizes, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            class="pagination-controls"
          />
          <div class="pagination-jump">
            跳至 
            <el-input-number 
              v-model="jumpPage" 
              :min="1" 
              :max="Math.ceil(total / pageSize)"
              size="small"
              style="width: 60px"
            />
            页
          </div>
        </div>

        <!-- 底部版权信息 -->
        <div class="footer">
          <p>Copyright © Assistants. All Rights Reserved.</p>
          <p>Email : 1195193561@qq.com WeChat: zz1195193561</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Document } from '@element-plus/icons-vue'

// 响应式数据
const loading = ref(false)
const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(4)
const jumpPage = ref(1)

// 搜索表单
const searchForm = reactive({
  keyword: '',
  createTime: '',
  category: ''
})

// 表格数据
const tableData = ref([])

// 模拟数据
const mockData = [
  {
    id: 1,
    fileName: '高中数学第三册第4章平行线的性质与判定',
    fileSize: '158KB',
    uploadTime: '2019-07-17 10:10:07'
  },
  {
    id: 2,
    fileName: '高中数学第三册第4章平行线的性质与判定',
    fileSize: '158KB',
    uploadTime: '2019-07-17 10:10:07'
  },
  {
    id: 3,
    fileName: '高中数学第三册第4章平行线的性质与判定',
    fileSize: '158KB',
    uploadTime: '2019-07-17 10:10:07'
  },
  {
    id: 4,
    fileName: '高中数学第三册第4章平行线的性质与判定',
    fileSize: '158KB',
    uploadTime: '2019-07-17 10:10:07'
  },
  {
    id: 5,
    fileName: '高中数学第三册第4章平行线的性质与判定',
    fileSize: '158KB',
    uploadTime: '2019-07-17 10:10:07'
  },
  {
    id: 6,
    fileName: '高中数学第三册第4章平行线的性质与判定',
    fileSize: '158M',
    uploadTime: '2019-07-17 10:10:07'
  }
]

// 搜索
const handleSearch = () => {
  loading.value = true
  // 模拟搜索延迟
  setTimeout(() => {
    loadData()
    loading.value = false
    ElMessage.success('搜索完成')
  }, 500)
}

// 新增文档
const handleAdd = () => {
  ElMessage.info('新增文档功能')
}

// 编辑/删除文档
const handleEdit = (row) => {
  ElMessageBox.confirm(`确定要删除文档"${row.fileName}"吗？`, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    ElMessage.success('删除成功')
  }).catch(() => {
    ElMessage.info('已取消删除')
  })
}

// 分页大小改变
const handleSizeChange = (val) => {
  pageSize.value = val
  loadData()
}

// 当前页改变
const handleCurrentChange = (val) => {
  currentPage.value = val
  loadData()
}

// 退出登录
const logout = () => {
  ElMessageBox.confirm('确定要退出登录吗？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    ElMessage.success('退出成功')
  })
}

// 加载数据
const loadData = () => {
  loading.value = true
  // 模拟API调用
  setTimeout(() => {
    tableData.value = mockData.slice(0, 6)
    total.value = mockData.length
    loading.value = false
  }, 300)
}

// 组件挂载时加载数据
onMounted(() => {
  loadData()
})
</script>

<style scoped>
.document-management {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: #f0f2f5;
}

/* 顶部导航栏 */
.header {
  height: 60px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  color: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.header-left {
  display: flex;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  font-size: 18px;
  font-weight: bold;
}

.logo-icon {
  font-size: 24px;
  margin-right: 8px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 15px;
}

.user-info {
  font-size: 14px;
}

.logout-btn {
  color: white !important;
}

/* 主容器 */
.main-container {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* 左侧菜单 */
.sidebar {
  width: 200px;
  background-color: #f5f5f5;
  border-right: 1px solid #e6e6e6;
  overflow-y: auto;
}

.sidebar-menu {
  border: none;
  height: 100%;
}

.sidebar-menu .el-menu-item {
  height: 50px;
  line-height: 50px;
  font-size: 14px;
}

.sidebar-menu .el-menu-item.is-active {
  background-color: #e6f7ff;
  border-right: 3px solid #409EFF;
}

/* 内容区域 */
.content {
  flex: 1;
  padding: 20px;
  background-color: #f8f9fa;
  overflow-y: auto;
}

.content-header {
  margin-bottom: 20px;
}

.content-header h2 {
  margin: 0;
  color: #333;
  font-size: 24px;
  font-weight: 500;
}

/* 搜索区域 */
.search-section {
  background: white;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.search-form {
  margin: 0;
}

.search-form .el-form-item {
  margin-right: 20px;
  margin-bottom: 0;
}

/* 表格区域 */
.table-section {
  background: white;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.file-name {
  display: flex;
  align-items: center;
  gap: 8px;
}

.file-icon {
  color: #409EFF;
  font-size: 16px;
}

/* 分页区域 */
.pagination-section {
  background: white;
  padding: 15px 20px;
  border-radius: 8px;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pagination-info {
  font-size: 14px;
  color: #666;
}

.pagination-controls {
  flex: 1;
  display: flex;
  justify-content: center;
}

.pagination-jump {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 14px;
  color: #666;
}

/* 底部版权 */
.footer {
  background: white;
  padding: 20px;
  border-radius: 8px;
  text-align: center;
  color: #999;
  font-size: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.footer p {
  margin: 5px 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .sidebar {
    width: 60px;
  }
  
  .sidebar-menu .el-menu-item span {
    display: none;
  }
  
  .search-form {
    flex-direction: column;
  }
  
  .search-form .el-form-item {
    margin-right: 0;
    margin-bottom: 10px;
  }
  
  .pagination-section {
    flex-direction: column;
    gap: 10px;
  }
}

/* 表格样式优化 */
:deep(.el-table) {
  font-size: 14px;
}

:deep(.el-table th) {
  background-color: #fafafa;
  color: #333;
  font-weight: 600;
}

:deep(.el-table td) {
  padding: 12px 0;
}

:deep(.el-table .el-table__row:hover) {
  background-color: #f5f7fa;
}

/* 按钮样式 */
.el-button {
  border-radius: 4px;
}

/* 输入框样式 */
:deep(.el-input__wrapper) {
  border-radius: 4px;
}

:deep(.el-date-editor) {
  border-radius: 4px;
}

/* 分页样式 */
:deep(.el-pagination) {
  --el-pagination-font-size: 14px;
}

:deep(.el-pagination .el-pager li) {
  border-radius: 4px;
  margin: 0 2px;
}

:deep(.el-pagination .btn-prev),
:deep(.el-pagination .btn-next) {
  border-radius: 4px;
}
</style>